package com.linx.open.controller;

import com.linx.common.core.domain.R;
import com.linx.common.core.validate.AddGroup;
import com.linx.common.core.validate.EditGroup;
import com.linx.common.web.core.BaseController;
import com.linx.open.domain.bo.YsyjLogBo;
import com.linx.open.domain.vo.YsyjLogVo;
import com.linx.open.service.IYsyjLogService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 第三方日志
 *
 * @author linx
 * @date 2024-10-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/open/log")
public class YsyjLogController extends BaseController {

    private final IYsyjLogService ysyjLogService;

    /**
     * 日志列表
     */
    @PostMapping("/list")
    public List<YsyjLogVo> export(YsyjLogBo bo, HttpServletResponse response) {
        List<YsyjLogVo> list = ysyjLogService.queryList(bo);
        return list;
    }

    /**
     * 获取第三方日志详细信息
     *
     * @param ysyjLogId 主键
     */
    @GetMapping("/{ysyjLogId}")
    public R<YsyjLogVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long ysyjLogId) {
        return R.ok(ysyjLogService.queryById(ysyjLogId));
    }

    /**
     * 新增第三方日志
     */
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody YsyjLogBo bo) {
        return toAjax(ysyjLogService.insertByBo(bo));
    }

    /**
     * 修改第三方日志
     */
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody YsyjLogBo bo) {
        return toAjax(ysyjLogService.updateByBo(bo));
    }

}
